<?php
/**
 * Created by PhpStorm.
 * User: admin
 * Date: 2016/11/25
 * Time: 13:57
 * 支付记录
 */
require('../include/init.inc.php');
$method = $page_no = $start_date = $end_date = $user_name = $search = '';
extract($_REQUEST, EXTR_IF_EXISTS);


if ($search) {
    if ($start_date == '' || $end_date == '') {
        echo '开始时间或者结束时间都不能为空';
        exit;
    }

    $start_time = strtotime($start_date);
    $end_time = strtotime($end_date) + (23 * 3600) + (59 * 60) + 59;

    if ($start_time > $end_time) {
        echo '开始时间不能小于结束时间';
        exit;
    }

    if (($end_time - $start_time) > 30 * 24 * 3600) {
        echo '查询周期不能操作30天';
        exit;
    }


    $search_str = " WHERE createtime >= '$start_time' and createtime <= '$end_time'";
    if ($user_name != '') {
        $search_str .= " AND user_name = '$user_name'";
    } else {
        $search_str .= " AND 1=1";
    }
    $row_count = AdminPayLog::getCountBySearch($search_str);
    $page_size = PAGE_SIZE;
    $page_no = $page_no < 1 ? 1 : $page_no;

    $total_page = $row_count % $page_size == 0 ? $row_count / $page_size : ceil($row_count / $page_size);
    $total_page = $total_page < 1 ? 1 : $total_page;
    $page_no = $page_no > ($total_page) ? ($total_page) : $page_no;
    $start = ($page_no - 1) * $page_size;


    $payLogs = AdminPayLog::getAllPayLogs($start, $page_size, $search_str);

    foreach ($payLogs as $ord) {
        $new_order['OrderID'] = $ord['OrderID'];
        $new_order['MerchantID'] = $ord['MerchantID'];
        $new_order['TransNo'] = $ord['TransNo'];
        $new_order['Currency'] = $ord['Currency'];
        $new_order['Amount'] = $ord['Amount'];
        $new_order['Version'] = $ord['Version'];
        $new_order['BName'] = $ord['BName'];
        $new_order['BEmail'] = $ord['BEmail'];
        $new_order['BAddress'] = $ord['BAddress'];
        $new_order['BCity'] = $ord['BCity'];
//    $new_order['BState'] = $ord['BState'];
//    $new_order['BPostcode'] = $ord['BPostcode'];
//    $new_order['BCountry'] = $ord['BCountry'];
        $new_order['BPhone'] = $ord['BPhone'];
        $new_order['CardNumber'] = $ord['CardNumber'];
//    $new_order['CardMonth'] = $ord['CardMonth'];
//    $new_order['CardYear'] = $ord['CardYear'];
//    $new_order['CardCvv'] = $ord['CardCvv'];
        $new_order['URL'] = $ord['URL'];
        $new_order['IP'] = $ord['IP'];
        $new_order['UserAgent'] = $ord['UserAgent'];
        $new_order['AcceptLanguage'] = $ord['AcceptLanguage'];
        $new_order['Products'] = $ord['Products'];
        $new_order['RetCode'] = $ord['RetCode'];
        $new_order['RetStatus'] = $ord['RetStatus'];
        $new_order['RetMsg'] = $ord['RetMsg'];


        $new_order['createtime'] = date("Y-m-d H:i:s", $ord['createtime']);
        $new_order['modifytime'] = date("Y-m-d H:i:s", $ord['modifytime']);
        $real_logs[] = $new_order;
    }


    $page_html = Pagination::showPager("pay_log.php?start_date=" . $start_date . "&end_date=" . $end_date . "&user_name=" . $user_name . "&search=" . $search, $page_no, PAGE_SIZE, $row_count);

    Template::assign('page_no', $page_no);
    Template::assign('page_size', PAGE_SIZE);
    Template::assign('row_count', $row_count);
    Template::assign('page_html', $page_html);

}

$confirm_html = OSAdmin::renderJsConfirm("icon-remove");
Template::assign('osadmin_action_confirm', $confirm_html);
Template::assign('payLogs', $real_logs);
Template::display('pay_manage/pay_log.tpl');